
export const mixins = {
    data() {
        return {
            web3: null,
            usdt: null,
            usdtAmount: 0,


        };
    },
    computed: {},
    created() {
        this.$nextTick(() => {
            if (this.account == "") {
                var time;
                time = setInterval(() => {
                    this.account = this.$store.state.wallet.account;
                    if (this.account != "") {
                        clearInterval(time);
                        this.start();
                    }
                }, 1200);
            }
        });

    },

    methods: {
        start() {
            this.web3 = this.$store.state.wallet.web3;
            this.usdt = this.$store.state.wallet.contract["usdt"];
            this.getBalacne()
            this.starts()
        },
        getBalacne() {
            this.blockFun.getEthBalance('usdt').then(res => {
                this.usdtAmount =  Math.floor(res * 10000) / 10000;
                console.log(res)
            })

        },
        success(){
            this.$toast.clear()
            this.$toast.success()
            this.starts()

        },
        fail(){
            this.$toast.clear()

            this.$toast.fail()
            this.starts()

        },
        toWei(num) {
            if (num) {
                return this.web3.utils.toWei(String(num), "ether")
            } else {
                return 0
            }
        },

        fromWei(num) {
           if(this.web3){
               if (num) {
                   return Number(this.web3.utils.fromWei(String(num), "ether"));
               } else {
                   return 0
               }
           }
        },
        disPlayAddress(address, one = 8, two = 8) {
            if (address) {
                let str1 = address.substring(0, one);
                let str2 = address.substring(address.length - two, address.length);
                let subStr = str1 + "…" + str2;
                return subStr;
            }
        },
        copy(incode) {
            this.$copyText(incode).then(() => {
                this.$toast.success(this.$t("m.复制成功"));
            });
        },

    },
};
